package leetcode.code0696;

public class Solution {
	public int countBinarySubstrings(String s) {
		int n = s.length();
		int p = 0;
		int ans = 0;
		int last = 0;
		while (p < n) {
			char c = s.charAt(p);
			int cnt = 0;
			while (p < n && s.charAt(p) == c) {
				p++;
				cnt++;
			}
			ans += Math.min(last, cnt);
			last = cnt;
		}
		return ans;
	}
}
